package com.gitee.feizns.webtemplate.commons.upload.processor.impl;

import com.gitee.feizns.webtemplate.commons.upload.MediaType;
import com.gitee.feizns.webtemplate.commons.upload.UploadEvent;
import com.gitee.feizns.webtemplate.commons.upload.UploadProperties;
import com.gitee.feizns.webtemplate.commons.upload.processor.Processor;
import com.gitee.feizns.webtemplate.commons.utils.RequestUtils;
import com.gitee.feizns.webtemplate.commons.utils.file.FileUtils;

import java.util.Map;

/**
 * web文件写入
 * @author feizns
 * @since 2019/5/15
 */
public class WebDirProcessor implements Processor {

    @Override
    public Map<MediaType, String[]> getProperty(UploadProperties uploadProperties) {
        return uploadProperties.getWebUploadDirs();
    }

    @Override
    public void write(UploadEvent event, String dir, UploadProperties properties) {
        FileUtils.write(event.getInputStream(), RequestUtils.getRealPath(dir) + event.getFilename());
    }

}
